﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_CodgConfig : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainNoDictRule");

            migrationBuilder.DropTable(
                name: "MainStdTableRestrRule");

            migrationBuilder.DropTable(
                name: "MainNoDict");

            migrationBuilder.CreateTable(
                name: "MainCodgConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Codg = table.Column<string>(type: "text", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainCodgConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainCodgConfigRule",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    NoDictRuleType = table.Column<int>(type: "integer", nullable: false),
                    Len = table.Column<int>(type: "integer", nullable: false),
                    Format = table.Column<string>(type: "text", nullable: false),
                    DefaultValue = table.Column<string>(type: "text", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    CodgConfigId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainCodgConfigRule", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainCodgConfigRule_MainCodgConfig_CodgConfigId",
                        column: x => x.CodgConfigId,
                        principalTable: "MainCodgConfig",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainCodgConfigRule_CodgConfigId",
                table: "MainCodgConfigRule",
                column: "CodgConfigId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainCodgConfigRule");

            migrationBuilder.DropTable(
                name: "MainCodgConfig");

            migrationBuilder.CreateTable(
                name: "MainNoDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Codg = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainNoDict", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainStdTableRestrRule",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StdTableColumnDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdTableDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    RestrRuleValue = table.Column<string>(type: "text", nullable: true),
                    TableRestrRuleProvider = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdTableRestrRule", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdTableRestrRule_MainStdTableColumnDict_StdTableColumn~",
                        column: x => x.StdTableColumnDictId,
                        principalTable: "MainStdTableColumnDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainStdTableRestrRule_MainStdTableDict_StdTableDictId",
                        column: x => x.StdTableDictId,
                        principalTable: "MainStdTableDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainNoDictRule",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DefaultValue = table.Column<string>(type: "text", nullable: true),
                    Format = table.Column<string>(type: "text", nullable: false),
                    Len = table.Column<int>(type: "integer", nullable: false),
                    NoDictId = table.Column<Guid>(type: "uuid", nullable: true),
                    NoDictRuleType = table.Column<int>(type: "integer", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainNoDictRule", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainNoDictRule_MainNoDict_NoDictId",
                        column: x => x.NoDictId,
                        principalTable: "MainNoDict",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainNoDictRule_NoDictId",
                table: "MainNoDictRule",
                column: "NoDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdTableRestrRule_StdTableColumnDictId",
                table: "MainStdTableRestrRule",
                column: "StdTableColumnDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdTableRestrRule_StdTableDictId",
                table: "MainStdTableRestrRule",
                column: "StdTableDictId");
        }
    }
}
